package com.thinkit.bigdata.web.controller.dataMining;

import com.thinkit.bigdata.core.util.es.ESUtil;
import com.thinkit.bigdata.web.model.result.HtmlResult;
import com.thinkit.bigdata.web.service.dataMining.BusTrendViewService;
import com.thinkit.bigdata.web.service.impl.audioSearch.AudioSearchPubMetImpl;
import org.apache.log4j.Logger;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * 数据挖掘
 */
@RestController
@RequestMapping("/data-mining")
public class BusTrendViewController {

    private static Logger logger = Logger.getLogger(BusTrendViewController.class);

    @Resource
    private BusTrendViewService viewService;

    @Resource
    private ESUtil esUtil;

    @RequestMapping(value = "/get-data-by-mes", method = RequestMethod.POST)
    public HtmlResult getDateList(HttpServletRequest request) {
        String logTxt = "【数据挖掘-音频列表方法】";
        logger.info(logTxt);
        try {
            String pageNum = request.getParameter("pageNum");//起始页
            String pageSize = request.getParameter("pageSize");//每页条数
            String sortName = request.getParameter("sortName");//录音流水
            String sortOrder = request.getParameter("sortOrder");//录音流水
            logger.info(logTxt + "pageNum = " + pageNum);
            logger.info(logTxt + "pageSize = " + pageSize);
            logger.info(logTxt + "sortName = " + sortName);
            logger.info(logTxt + "sortOrder = " + sortOrder);
            return viewService.getDateList(request);
        } catch (Exception e) {
            return HtmlResult.failure(logTxt + Arrays.toString(e.getStackTrace()));
        }
    }

    @RequestMapping(value = "/export-data-mes", method = RequestMethod.POST)
    public void exportMyAss(HttpServletRequest request, HttpServletResponse response) {
        String logTxt = "【话单信息-导出】";
        logger.info(logTxt);
        try {
            BoolQueryBuilder boolQuery = viewService.getQuery(logTxt, request);
            new AudioSearchPubMetImpl().exportMyAss(logTxt, request, response, boolQuery, esUtil);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
